import 'package:flutter/material.dart';

class MyHide extends StatefulWidget {
  final bool visible;
  final Widget child;
  final Duration duration;
  const MyHide(
      {super.key,
      required this.visible,
      required this.child,
      this.duration = const Duration(milliseconds: 300)});

  @override
  State<MyHide> createState() => _MyHideState();
}

class _MyHideState extends State<MyHide> {
  bool _visible = true;

  @override
  Widget build(BuildContext context) {
    return AnimatedOpacity(
        opacity: widget.visible ? 1.0 : 0.0,
        duration: widget.duration,
        curve: Curves.fastOutSlowIn,
        onEnd: () {
          //logd("MyHide", "onEnd: ${widget.visible}");
          setState(() {
            _visible = widget.visible;
          });
        },
        child: Visibility(
          visible: widget.visible ? true : _visible,
          child: widget.child,
        ));
  }
}
